'use strict';
const md5 = require('md5');
const Controller = require('./base');

class AuthController extends Controller {
  async login() {
    const { ctx, service } = this;
    const { username, password } = ctx.request.body;
    const md5pwd = md5(password);
    const where = { username, password: md5pwd };
    const result = await service.auth.login({ where });
    await this.success(result);
  }

  async getUserInfo() {
    const { ctx, service } = this;
    const { token } = ctx.request.query;
    const userinfo = await service.auth.getUserInfo(token);
    await this.success(userinfo);
  }

  async getUserList() {
    const { service } = this;
    const userList = await service.auth.getUserList();
    await this.success(userList);
  }
}

module.exports = AuthController;
